/-app
/-files ...
FileTree.ts
SyncStorageAccess.ts
/-imports
/-storage
/-typings
functions.ts
index.html
try.js
xxxxxxxxxx
    fullPath: string,
31
    
32
    
33
  }
34
​
35
  interface Entry {
36
    
37
    li: HTMLLIElement;
38
    name: string;
39
    fullPath: string;
40
​
41
    children: Entry[];
42
    
43
  }
44
​
45
  function findEntry(
46
    fullPath: string,
47
    path: string,
48
    entries: Entry[],
49
    createIfAbsent: boolean): Entry {
50
    
51
    var name: string, restPath: string;
52
​
53
      
54
    var slashPos = path.indexOf('/');
55
    while (!slashPos) { // slight normalization, keep it for the sake of root paths
56
      path = path.slice(1);
57
      slashPos = path.indexOf('/');
58
    }
59
      
60
    if (slashPos < 0) {
61
      name = path;
62
      restPath = null;
63
    }
64
    else {
65
      name = path.slice(0, slashPos);
66
      restPath = path.slice(slashPos + 1);
67
    }
68
    
69
    var seekResult = _seekEntryNonRecursive(name, entries);
70
    var nextEntry: Entry;
71
      
72
    if (seekResult.insert) {
73
      if (!createIfAbsent) return null;
74
      
75
      nextEntry = _createNewEntry(fullPath, name);
76
      entries.splice(seekResult.index, 0, nextEntry);
77
    }
78
    else {
79
      nextEntry = entries[<any>seekResult];
80
    }
81
      
82
      
83
    if (restPath)
84
      return findEntry(fullPath, restPath, nextEntry.children, createIfAbsent);
85
    else
86
      return nextEntry;
87
​
88
  }
89
​
90
  function _createNewEntry(fullPath: string, name: string): Entry { 
91
    var li = document.createElement('li');
92
    li.textContent = name; // fullPath ?
93
    // TODO: create LI, add to parent, create Entry and return
94
  }
95
​
96
  /** Returns either number (succeess) or complex obj (failure) */
97
  function _seekEntryNonRecursive(
98
    name: string,
99
    entries: Entry[]): { insert: boolean; index: number } {
100
    if (entries.length==0)
101
      return null;
102
    
103
    if (entries[0].name > name)
104
      return { insert: true, index: 0 };
105
    if (entries[0].name === name)
106
      return <any>0;
107
    
108
    var lowIndex = 0;
109
    
89:25 function (fullPath: string, name: string) => Entry